package com.example.reagent_management.service.works

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.example.reagent_management.ui.message.pojo.MessageRepository
import com.example.reagent_management.ui.operatedialog.repository.HistoryRepository
import com.example.reagent_management.ui.operatedialog.repository.StoreRepository
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

@HiltWorker
class CleanWork @AssistedInject constructor(
    @Assisted context: Context,
    @Assisted workerParameters: WorkerParameters,
    private val historyRepository: HistoryRepository,
    private val messageRepository: MessageRepository,
    private val storeRepository: StoreRepository
) :
    CoroutineWorker(context, workerParameters) {
    override suspend fun doWork(): Result {
        return withContext(Dispatchers.IO) {
            historyRepository.cleanHistory()
            messageRepository.cleanMessage()
            storeRepository.cleanStore()
            Result.success()
        }
    }
}